<template>
<!-- 楼宇明细 -->
  <div>
    <div class="ly-img">
      <img src="~@/assets/imgs/publicline/board/icon-users-group.png" />
      <span class="title">楼宇端口占用率>70%</span>
    </div>
    <van-list
      v-model="loading"
      loading-text="加载中"
      :finished="finished"
      finished-text="没有更多了"
      @load="onload"
    >
      <div class="detail-info" v-for="(item,index) in list" :key="index">
        <div class="info-detail">
          <span class="info-name">{{ item.XQ_NAME }}</span>
          <span class="info-flag">{{ item.BUILD_NAME }}</span>
        </div>
        <div class="info-tc">
          <div class="info-desc">端口数<span>{{ item.PORT_NUM }}</span></div>
          <div class="info-desc">宽带用户数<span>{{ item.KD_USER }}</span></div>
          <div class="info-desc">端口占用率<span>{{ item.USE_PORT_NUM }}</span></div>
          <div class="info-desc">融合用户数<span>{{ item.COMB_NUM }}</span></div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { Toast } from 'vant'
import { warnLyDetail } from '@/api/publicline/board.js'

export default {
  components: {},
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 15
      },
      loading: false,
      finished: false,
      list: [],
    }
  },
  created() {
    this.loadData()
  },
  beforeDestroy() {
    Toast.clear()
  },
  methods: {
    async loadData(force) {
      // 改变搜索条件，重新查询
      if ( force ) {
        this.queryParams.pageNum = 1
        this.list = []
        this.finished = false
      }
      this.loading = true
      const res = await warnLyDetail({ ...this.queryParams, gridId: this.$dataPermission })
      const { result, success } = res
      if(success) {
        this.loading = false
        if(result.list.length < this.queryParams.pageSize) {
          this.finished = true
          Toast({
            message: '已全部加载',
            duration: 500,
            position: 'bottom',
            forbidClick: 'true'
          });
        }
        this.list = this.list.concat(result.list)
        Toast.clear()
      }
    },
    onload() {
      this.loading = false
      if(this.finished === false) {
        Toast({
          type:'loading',
          duration: 0,
          message: '正在加载',
          position: 'bottom',
          forbidClick: 'true'
        })
        this.queryParams.pageNum = parseInt(this.queryParams.pageNum) + 1
        this.loadData()
      } else {
        Toast({
          message: '已全部加载',
          duration: 500,
          position: 'bottom',
          forbidClick: 'true'
        })
      }
    },
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/person.less';
.ly-img {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  img {
    width: 16px;
  }
  .title {
    color: #333;
    font-size: 16px;
    margin-left: 6px;
  }
}
.detail-info {
  align-items: flex-start;
  flex-direction: column;

  .info-tc {
    flex-wrap: wrap;
  }
  .info-desc {
    width: 50%;
    > span {
      padding-left: 12px;
      color: #4D98FF;
    }
  }
}
</style>